//
//  YCMyOrderViewController.m
//  YCVillageDoctor
//
//  Created by zhangxiaoliang on 2017/7/26.
//  Copyright © 2017年 zhangxiaoliang. All rights reserved.
//

#import "YCMyOrderViewController.h"
#import "YCAllOrderview.h"
#import "YCOrderListViewController.h"



@interface YCMyOrderViewController ()<UIScrollViewDelegate,YCAllOrderviewDelegate>
@property (nonatomic, strong)YCAllOrderview *headerView;
@property (nonatomic, strong)UIScrollView *scrollView;
@end

@implementation YCMyOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"全部订单";
    [self buildUI];
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(pushVcNoti:) name:@"kPushVcNoti" object:nil];
    
    
}
- (void)pushVcNoti:(NSNotification *)noti
{
    
    [self.navigationController pushViewController:noti.object animated:YES];
}
-(void)buildUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    //头部的view
    self.headerView = [YCAllOrderview loadFromNib:@"YCAllOrderview" ];
    self.headerView.delegate = self;
    [self.view addSubview:self.headerView];
    
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.equalTo(self.view);
        make.height.equalTo(@45);
    }];
    
    //scrollView
    self.scrollView = [[UIScrollView alloc]init];
    self.scrollView.delegate = self;
    self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * 5, 0);
    self.scrollView.bounces = YES;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    
    [self.view addSubview:self.scrollView];
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.equalTo(self.view);
        make.top.equalTo(self.view).offset(45);
    }];
    
    
    for (int i = 0; i < 5; i ++) {
        
        YCOrderListViewController *orderListVC = [[YCOrderListViewController alloc]init];
        orderListVC.pushType = i;
        orderListVC.view.frame = CGRectMake(SCREEN_WIDTH * i, 0, self.scrollView.width, self.scrollView.height);
        [self.scrollView addSubview:orderListVC.view];
    }
    
}

#pragma - UIScrollViewDelegate
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    NSInteger index = scrollView.contentOffset.x / scrollView.width;
    UIButton *btn = [self.headerView.buttons objectAtIndex:index];
    [self.headerView clickButton:btn];
    
}

#pragma - YCAllOrderviewDelegate
-(void)selectButton:(NSInteger)index{
    
    self.scrollView.contentOffset = CGPointMake(self.scrollView.width * index, 0);
}
@end
